<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript" src="<%=basePath %>/resource/js/common-css-js.js"></script>
<title>采购计划-审核</title>
<style type="text/css">
	body {
		margin: 10px;
	}
	
	.rem-border {
		border: unset;
	    width: 100%;
	    height: 100%;
	}
	
</style>
</head>
<body>
	<div class="layui-row layui-col-space10">
		<div class="layui-col-lg6 layui-col-md6">
			<blockquote class="layui-elem-quote title mag0">采购计划信息</blockquote>
			<table class="layui-table mag0">
				<colgroup>
					<col width="150">
					<col>
				</colgroup>
				<tbody id="baseInfo">
					<tr>
						<td>采购单号</td>
						<td class="procurePlanOrderNumber"></td>
					</tr>
					<tr>
						<td>采购主题</td>
						<td class="procurePlanTheme"></td>
					</tr>
					<tr>
						<td>计划员</td>
						<td class="procurePlanPlanner"></td>
					</tr>
					<tr>
						<td>采购员</td>
						<td class="procurePlanBuyer"></td>
					</tr>
					<tr>
						<td>金额预算</td>
						<td class="procurePlanAmountBudget"></td>
					</tr>
					<tr>
						<td>采购日期</td>
						<td class="procurePlanStartDate"></td>
					</tr>
					<tr>
						<td>截止日期</td>
						<td class="procurePlanEndDate"></td>
					</tr>
				</tbody>
			</table>
			<div style="margin-top: 10px;">
				<blockquote class="layui-elem-quote title mag0" style="margin-top: 10px;">供应商信息</blockquote>
				<table class="layui-table mag0">
					<colgroup>
						<col width="150">
						<col>
					</colgroup>
					<tbody id="supplierInfo">
						<tr>
							<td>供应商</td>
							<td class="supArchiEnterpriseName"></td>
						</tr>
						<tr>
							<td>联系人</td>
							<td class="supArchiLinkMan"></td>
						</tr>
						<tr>
							<td>联系方式</td>
							<td class="supArchiLinkPhone"></td>
						</tr>
						<tr>
							<td>QQ</td>
							<td class="supArchiQq"></td>
						</tr>
						<tr>
							<td>微信</td>
							<td class="supArchiWechat"></td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
		<div class="layui-col-lg6 layui-col-md6">
			<div>
				<blockquote class="layui-elem-quote title mag0">计划产品信息</blockquote>
				<table class="layui-table mag0">
					<colgroup>
						<col width="150">
						<col>
					</colgroup>
					<thead>
					    <tr>
					      <th lay-data="{field: 'productNameView', minWidth: '140'}">产品名称</th>
					      <th lay-data="{field: 'unitPriceView', sort: true, minWidth: '140'}">单价</th>
					      <th lay-data="{field: 'countView', sort: true, edit: 'text', minWidth: '140'}">数量</th>
					      <th lay-data="{field: 'totalView', sort: true, minWidth: '135'}">总价</th>
					    </tr>
				  	</thead>
					<tbody id="productInfo">
					</tbody>
				</table>
			</div>
			<div style="margin-top: 10px;">
				<blockquote class="layui-elem-quote title mag0">总款</blockquote>
				<table class="layui-table mag0">
					<colgroup>
						<col width="150">
						<col>
					</colgroup>
					<tbody>
						<tr>
							<td>总款额</td>
							<td id="TotalMoney"></td>
						</tr>
					</tbody>
			   </table>
			</div>
		</div>
		<div class="layui-col-lg6 layui-col-md6">
			<blockquote class="layui-elem-quote title mag0">审核</blockquote>
			<form id="submitForm">
				<table class="layui-table mag0">
					<colgroup>
						<col width="150">
						<col>
					</colgroup>
					<tbody id="supplierInfo">
							<tr>
								<td>账号</td>
								<td id="procureOrderCheckAccount">${user.userName}</td>
							</tr>
							<tr>
								<td>状态</td>
								<td>
								  <input id="check_status_ok" checked type="radio" name="check_status" value="3" title="审核通过">
							      <label for="check_status_ok">审核通过</label>
							      
							      <input id="check_status_no" type="radio" name="check_status" value="4" title="审核不通过">
							      <label for="check_status_no">审核不通过</label>
							      
							      <input id="check_status_again" type="radio" name="check_status" value="5" title="重新安排">
							      <label for="check_status_again">重新安排</label>
								</td>
							</tr>
							<tr>
								<td>备注</td>
								<td>
									<textarea name="remark" required="required" rows="5" style="width:100%"></textarea>
								</td>
							</tr>
							<tr>
								<td>签名</td>
								<td><input type="text" name="sign" class="rem-border" required="required" /></td>
							</tr>
							<tr>
								<td>操作</td>
								<td><input type="button" onclick="submitForm()" value="提交" class="layui-btn layui-btn-primary layui-btn-sm"/></td>
							</tr>
					</tbody>
				</table>
			</form>
		</div>
	</div>
	<script type="text/javascript">
		
		var selectedObj = parent.cTable.bootstrapTable('getSelections');
		
		var baseEle = $("#baseInfo");
		
		//采购计划信息 table生成
		for(key in selectedObj[0]){
			baseEle.find("td[class='"+key+"']").text(selectedObj[0][key]);
		}
		
		var productEle = $("#productInfo");
		
		//查询当前采购计划对应的产品
		var procurementPlan = requestData(path+"/procurement/procurement-plan/"+selectedObj[0].procurePlanId);
		
		//查询产品的详细信息
		var detailProduct = requestData(path+"/procurement/production-prise/prodId="+
				procurementPlan.prodId.substring(0,procurementPlan.prodId.length - 1));
		
		//查询产品对应的供应商
		var supplierArchives = requestData(path+"/procurement/supplier-archives/supId="+procurementPlan.supArchiId);
		
		//取出采购数量
		var productCountArray = procurementPlan.prodBuyCount.substring(0, procurementPlan.prodBuyCount.length - 1).split("-");
		
		//取出总价
		var productTotalMoneyArray = procurementPlan.prodTotalMoney.substring(0, procurementPlan.prodTotalMoney.length - 1).split("-");
		
		//生成产品信息
		for(var i = 0;i<detailProduct.data.length;i++){
			productEle.prepend(
					"<tr>"+
						"<td>"+detailProduct.data[i].prodName+"</td>"+
						"<td>"+detailProduct.data[i].prodPrice+"</td>"+
						"<td>"+productCountArray[i]+"</td>"+
						"<td>"+productTotalMoneyArray[i]+"</td>"+
					"</tr>"		
			);
		}
		
		//供应商信息
		for(key in supplierArchives){
			$("#supplierInfo td[class='"+key+"']").text(supplierArchives[key]);
		}
		//存储总额
		var TotalMoney = 0;
		for(var i = 0;i<productTotalMoneyArray.length;i++){
			TotalMoney+= parseInt(productTotalMoneyArray[i]);
		}
		$("#TotalMoney").text(TotalMoney+"元");
		
		function submitForm(){
			var formArray = $("#submitForm").serializeArray();
			//校验表单是否输入值
			if(formArray[1].value==""||formArray[2].value==""){
				//没有输入直接结束函数
				return;
			}
			//包装一个
			var orderInfo = {
					procureOrderCheckProcureId:selectedObj[0].procurePlanId,
					procureOrderCheckStatus:formArray[0].value,
					procureOrderCheckAccount:$("#procureOrderCheckAccount").text(),
					procureOrderCheckRemark:formArray[1].value,
					procureOrderCheckSign:formArray[2].value
			};
			$.ajax({
			   type: 'POST',
			   url: path+"/procure-order-info",
			   data: orderInfo,
			   contentType: "application/x-www-form-urlencoded;charset='UTF-8'",
			   statusCode: {
				   201: function(){
					   fixedAlert("审核操作成功!",1,true,true);
				   },
				   400: function() {
					   fixedAlert("审核操作失败!",0,false);
				   },
				   500: function(){
					   fixedAlert("服务器繁忙,请联系管理员!",2,false);
				   }
			   }
			});
		}
		
	</script>
</body>
</html>